package servlet.comm;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import factory.comm.HomeworkDAOFactory;
import vo.comm.Homework;

public class UpdateHomeworkServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public UpdateHomeworkServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String after_homeworkname=request.getParameter("after_homeworkname");
		String homeworkid=request.getParameter("homeworkid");
//		String before_homeworkname=request.getParameter("before_homeworkname");
		Homework homework=new Homework();
		homework.setHomeworkname(after_homeworkname);
		homework.setHomeworkid(homeworkid);
//		homework.setHomeworkname(before_homeworkname);
		response.setContentType("text/html; charset=UTF-8");

		try {
			if(HomeworkDAOFactory.getIHomeworkDAOInstance().doUpdate(homework)){
				response.sendRedirect("homework/update_success.jsp");
			}
			else{
				response.sendRedirect("homework/update_failure.jsp");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
